package br.com.dev.tcc.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import br.com.dev.tcc.R;
import br.com.dev.tcc.bean.Apolice;
import br.com.dev.tcc.bean.PlanoEnum;
import br.com.dev.tcc.bean.Segurado;
import br.com.dev.tcc.bean.Veiculo;

public class ConfirmProfileDialog extends Dialog {

	private OnConfirmListener listener;
	private Apolice apolice;
	
	public ConfirmProfileDialog(Context context, OnConfirmListener listener, Apolice apolice) {
		
		this(context);
		this.listener = listener;
		this.apolice = apolice;
		
		setListeners();
		setFields();
	}
	
	private ConfirmProfileDialog(Context context) {

		super(context, R.style.DialogAppTheme);

		super.getWindow();
		super.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.setContentView(R.layout.confirm_profile_dialog);
	}

	private void setFields() {

		((TextView) findViewById(R.id.tvValueApolice)).setText(apolice.getHash());
		int idPlano = apolice.getPlano().getId();
		((TextView) findViewById(R.id.tvValuePlano)).setText(PlanoEnum.getDescricao(idPlano));
		Segurado seg = apolice.getSegurado();
		((TextView) findViewById(R.id.tvValueNome)).setText(seg.getNome());
		Veiculo veic = apolice.getVeiculo();
		((TextView) findViewById(R.id.tvValuePlaca)).setText(veic.getPlaca());
		((TextView) findViewById(R.id.tvValueCor)).setText(veic.getCor());
		((TextView) findViewById(R.id.tvValueModelo)).setText(veic.getModelo());
	}

	private void setListeners() {

		findViewById(R.id.btConfirm).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				
				dismiss();
				listener.onConfirm();
			}
		});

		findViewById(R.id.btCancel).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				
				dismiss();
			}
		});
	}

	public void setListener(OnConfirmListener listener){
		
		this.listener = listener;
	}
	
	public interface OnConfirmListener {
		
		public void onConfirm();
	}
}
